<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE html>

<html>

	<head>

		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

		<title>仪器共享</title>

		<meta name="keywords" content="科研仪器，生命科学仪器，环境检测仪器，实验常用设备，分析仪器">

		<meta name="description" content="中国领先的科研仪器共享平台，让您快速找到各种类型的科学研究仪器。提升闲置仪器利用率，产生更大科研价值。涵盖：生命科学仪器、环境检测仪器、实验常用设备、分析仪器、仪表、物性测试、测量/计量仪器、在线及过程控制仪器。

">
		<!-- <link rel="stylesheet" href="new_css/header_footer.css?t=1"> -->
		<link rel="stylesheet" href="new_css/publishInstrument.css">
		<!-- <script src="js/jquery-1.11.3.js"></script> -->
		<script src="new_js/jquery-1.11.3.js"></script>
		<script src="js/jquery.pagination.min.js"></script>
		<script>
			$(function() {
				$('#front_header .header_wrap .right').hover(function() {
					$('#front_header .header_wrap .right .main .icon img').attr('src', 'images/icon2.png');
					$('#front_header .header_wrap .right .out').show();
				}, function() {
					$('#front_header .header_wrap .right .main .icon img').attr('src', 'images/icon1.png');
					$('#front_header .header_wrap .right .out').hide();
				});
				$('#sorts').on('mouseover', 'li', function() {
					$(this).find('span img').attr('src', 'images/icon4.png');
				});
				$('#sorts').on('mouseout', 'li', function() {
					$(this).find('span img').attr('src', 'images/icon5.png');
				});

				$('.mainList .content .left li').click(function() {
					$(this).addClass('selected').siblings().removeClass('selected');
				});
				//				$(".mainList .content .right table td input").each(function(){
				//					var index=$(this).parents('tr').index();
				//					$(this).attr('id','select'+index);
				//					$(this).siblings('label').attr('for','select'+index);
				//				});
				$(".mainList .content .right table td label").click(function() {
					if($(this).siblings('input').is(':checked')){
						$(this).find('img').attr('src','images/icon35.png');
						$(this).siblings('input').prop('checked',false);
					}else{
						$(this).find('img').attr('src','images/icon36.png');
						$(this).siblings('input').prop('checked',true);
					};
				});

			});
		</script>

	</head>

	<body style="background:#fff;">
		<%@include file="/header2.jsp"%>
		<div class="mainList">
			<div class="content">
				<div class="left">
					<div class="title">仪器管理</div>
					<div class="title_content">
						<!-- <div class="row1">仪器编号</div>
						<div class="row2">
							<input type="text" name="" id="" value="" />
						</div> -->
						<div class="row1">服务名称</div>
						<div class="row2">
							<input type="text" name="" id="serviceContent" value="" />
						</div>
						<div class="row1">单价大于</div>
						<div class="row2">
							<input type="text" name="" id="priceMore" value="" />
						</div>
						<div class="row3">
							<a id="search">查询</a>
						</div>
					</div>
				</div>
				<div class="right">
					<div class="title">
						<span>发布服务</span>
						<div class="title_btn">
							<a  id="export"><img src="images/icon31.png" /><span>导出</span></a>
							<!-- <a href="add18"><img src="images/icon32.png" /><span>添加</span></a>
							<a href="machine_user19"><img src="images/icon33.png" /><span>新增时间段方案</span></a> -->
							<a href="publishService21"><img src="images/icon34.png" /><span>发布服务</span></a>
						</div>
					</div>
					<table id="serviceTable">
						<tr>
							<th></th>
							<th>服务名称</th>
							<th>使用仪器</th>
							<th>服务内容</th>
							<th>服务收费</th>
							<th>状态</th>
							<th>操作</th>
						</tr>
					</table>
				</div>
			</div>
		
			
			<div class="pageButton">
			<div id="pagination3" class="page fl"></div>
			<!-- <div class="info fl">
				<p>当前页数：<span id="current3">1</span></p>
			</div> -->
			<input type="text" id="allinfonumber" style="display:none"/>
		</div>
	</div>
	<%@include file="/footer.jsp"%>
		
		

		<script>
			function yemian(serviceContent,priceMore){
					$.ajax({
						url :Server + "/serviceRelevant/servicePageList",
						//url :"http://localhost/serviceRelevant/servicePageList",
						data : {
							//"name":name,
							"limit":10,
							"offset":0,
							"serviceContent":serviceContent,
							"priceMore":priceMore,
							"uid":$("#useridoflogin").val()
							//"uid": "4d272484d5844be693c05443c4edd71e"
						},
						type : "POST",
						dataType: "JSON",
						success : function(data) {
							$("#pagination3").pagination({
								currentPage: 1,
								totalPage: Math.ceil(Number(data.total/10)),
								isShow: true,
								count: 7,
								homePageText: "首页",
								endPageText: "尾页",
								prevPageText: "<上一页",
								nextPageText: "下一页>",
								callback: function(current) {
									//$("#current3").text(current);
									findServiceByConditions(limit,$("#pagination3").pagination("getPage").current-1,"","");
								}
							});
						}
					});
				}
				function getUrlParam(name) {
       				 var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
   				     var r = window.location.search.substr(1).match(reg);  //匹配目标参数
 			    	 if (r != null) return unescape(r[2]); return null; //返回参数值
  					 }
				function GetUrlByParamName(name)
 			   {
  			      var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
 			       var URL =  decodeURI(window.location.search);
  			      var r = URL.substr(1).match(reg);
 			       if(r!=null){
 		           //decodeURI() 函数可对 encodeURI() 函数编码过的 URI 进行解码
 		           return  decodeURI(r[2]);
  			      };
  		      return null;
 			   };
			$(document).ready(function() {
					$("#serviceContent").val(GetUrlByParamName('serviceContent'));
					$("#priceMore").val(getUrlParam('priceMore'));
					limit = 10;
					offset = 0;
				//都不为空
				if(GetUrlByParamName('serviceContent')!=''&&getUrlParam('priceMore')!=''&&GetUrlByParamName('serviceContent')!=null&&getUrlParam('priceMore')!=null){
					//alert("1serviceContent="+GetUrlByParamName('serviceContent')+",priceMore="+getUrlParam('priceMore'));
					yemian(GetUrlByParamName('serviceContent'),getUrlParam('priceMore'));
					findServiceByConditions(limit,offset,GetUrlByParamName('serviceContent'),getUrlParam('priceMore'));
				//内容为空
				}else if(GetUrlByParamName('serviceContent')==''&&getUrlParam('priceMore')!=''){
					//alert("2serviceContent="+GetUrlByParamName('serviceContent')+",priceMore="+getUrlParam('priceMore'));
					yemian("",getUrlParam('priceMore'));
					findServiceByConditions(limit,offset,null,getUrlParam('priceMore'));
				//价格为空
				}else if(GetUrlByParamName('serviceContent')!=''&&getUrlParam('priceMore')==''){
					//alert("3serviceContent="+GetUrlByParamName('serviceContent')+",priceMore="+getUrlParam('priceMore'));
					yemian(GetUrlByParamName('serviceContent'),null);
					findServiceByConditions(limit,offset,GetUrlByParamName('serviceContent'),null);
				//都为空''
				}else if(GetUrlByParamName('serviceContent')==''&&getUrlParam('priceMore')==''){
					//alert("4serviceContent="+GetUrlByParamName('serviceContent')+",priceMore="+getUrlParam('priceMore'));
					yemian(null,null);
					findServiceByConditions(limit,offset,'',null);
				//都为空null
				}else if(GetUrlByParamName('serviceContent')==null&&getUrlParam('priceMore')==null){
					//alert("5serviceContent="+GetUrlByParamName('serviceContent')+",priceMore="+getUrlParam('priceMore'));
					yemian(null,null);
					findServiceByConditions(limit,offset,null,null);
				}
				
			});
			function findServiceByConditions(limit,offset,serviceContent,priceMore){
				$.ajax({
					url :Server + "/serviceRelevant/servicePageList",
					//url :"http://localhost/serviceRelevant/servicePageList",
					data : {
						"limit":10,
						"offset":offset,
						"serviceContent":serviceContent,
						"priceMore":priceMore,
						"uid":$("#useridoflogin").val()
						//"uid": "4d272484d5844be693c05443c4edd71e"
					},
					type : "POST",
					dataType: "JSON",
					success : function(data) {
						var html = "";
			          	var tr='<tr>\
							<td style="width: 6%">\
								<input type="checkbox" name="" id="" value="#0" />\
								<label><img src="images/icon35.png"/></label>\
							</td>\
							<td>#1</td>\
							<td>#2</td>\
							<td>#3</td>\
							<td>#6#7</td>\
							<td>#4</td>\
							<td>\
								<a class="index" onclick="findDeatail(#5,this)">查看</a>\
							</td>\
						</tr>';
						for (var i = 0; i < data.rows.length; i++) {
							var item = "";
							var status ="";
							var unit = (data.rows[i].unit == null)?'元/天':data.rows[i].unit;
							if(data.rows[i].sinsDetails!=undefined){
								if(data.rows[i].isCheck == 0)
									status = "审核中";
								if(data.rows[i].isCheck == 1)
									status = "已发布";
								if(data.rows[i].isCheck == 2)
									status = "审核失败";
								item += tr
									.replace("#0", data.rows[i].serviceId)
									.replace("#1", data.rows[i].serviceName)
									.replace("#2", data.rows[i].sinsDetails[0].chineseName)
									.replace("#3", data.rows[i].serviceContent)
									.replace("#4", status)
									.replace("#5", data.rows[i].serviceId)
									.replace("#6", data.rows[i].serviceFee)
									.replace("#7", unit)
								html += item;
							}else{
								if(data.rows[i].isCheck == 0)
									status = "审核中";
								if(data.rows[i].isCheck == 1)
									status = "已发布";
								if(data.rows[i].isCheck == 2)
									status = "审核失败";
								item += tr
									.replace("#0", data.rows[i].serviceId)
									.replace("#1", data.rows[i].serviceName)
									.replace("#2", "")
									.replace("#3", data.rows[i].serviceContent)
									.replace("#4", status)
									.replace("#5", data.rows[i].serviceId)
									.replace("#6", data.rows[i].serviceFee)
									.replace("#7", unit)
								html += item;
							}
						}
						var th="<tr><th></th><th>服务名称</th><th>使用仪器</th><th>服务内容</th><th>服务收费</th><th>状态</th><th>操作</th></tr>";
						
						$("#serviceTable").html(th+html);
						$(".mainList .content .right table td label").click(function() {
						if($(this).siblings('input').is(':checked')){
							$(this).find('img').attr('src','images/icon35.png');
							$(this).siblings('input').prop('checked',false);
						}else{
							$(this).find('img').attr('src','images/icon36.png');
							$(this).siblings('input').prop('checked',true);
						};
					});
						$("#search").click(function() {
							var serviceContent=$("#serviceContent").val();
							var priceMore=$("#priceMore").val();
							$(location).attr('href', 'Service_list?serviceContent=' + serviceContent + '&priceMore='+priceMore);
							
						});
						$("#export").click(function() {
							var idStr="";
							var allIdStr="";
							 for(i=0;i<$('img').length;i++){
								 if($('img').eq(i).attr("src")=="images/icon35.png"){
									allIdStr=allIdStr+$('img').eq(i).parent().prev().val()+","
								}
								if($('img').eq(i).attr("src")=="images/icon36.png"){
									idStr=idStr+$('img').eq(i).parent().prev().val()+","
								} 
							}
							if(idStr==""){
								//alert("请至少选择一条服务再导出");
								//return false;
								idStr=allIdStr;
							} 
							//window.location.href="http://localhost/serviceRelevant/serviceExportExcel?idStr="+idStr;
							window.location.href=Server+"/serviceRelevant/serviceExportExcel?idStr="+idStr;
							/* $.ajax({
							//url :Server + "/fon/infolist",
							url :"http://localhost/serviceRelevant/serviceExportExcel",
							data : {
								"idStr":idStr
							},
							type : "POST",
							dataType: "JSON",
							success : function(data) {
								
							}
						}); */
					});
						$(".index").each(function() {
							if($(this).parent().prev().text()=="审核中"){
								$(this).text("修改");
							}
						});
					},
				});
			}
			
			function findDeatail(id,e) {
				if($(e).text()=="修改"){
					$(location).attr('href', 'publishService21?serviceId=' + id + '&modify=true');
				}else{
					$(location).attr('href', 'publishService21?serviceId=' + id + '&modify=false');
				}
	           //$(location).attr('href', 'publishService21?serviceId=' + id + '');
            }
		</script>


	</body>
<style>

	.pageButton {
	padding: 20px 0 29px 0;
	width: 1200px;
	margin: 0 auto;
	text-align: right;
	}
	.ui-pagination-container {
		width: 1000px;
		height: 100px;
	}


	a.ui-pagination-page-item.active12345 {
		width: 35px;
		height: 35px;
		display: inline-block;
		background: #ff8a00;
		text-align: center;
		line-height: 35px;
		color: #fff;
		border-radius: 2px;
	}
	a.ui-pagination-page-item {
		width: 35px;
		text-align: center;
		line-height: 35px;
		border-radius: 2px;
		margin-right: 10px;
		display: inline-block;
		border: 1px solid #ccc;
	}
	a.ui-pagination-page-btn {
		width: 35px;
		height: 35px;
		display: inline-block;
		text-align: center;
		line-height: 35px;
		border-radius: 2px;
		margin-right: 10px;
		margin-left: 10px;
	}



	a.ui-pagination-page-item.nextPage, a.ui-pagination-page-item.prevPage,a.ui-pagination-page-item.endPage, a.ui-pagination-page-item.homePage{
		line-height: 35px;
		/* color: #fff; */
		border-radius: 2px;
		margin-right: 10px;
		/* padding-right: 20px; */
		display: inline-block;
		border: 1px solid #ccc;
		width: 100px;
	}
	.mainList .content .right table {
		margin-top: 14px;
		width: 100%;
		border-collapse: collapse;
		border: 1px solid #d3d3d3;
		height: 45px;
		box-shadow: 0 0 10px 2px rgba(254,244,232,0.8);
	}
	tr {
		height: 88px;
	}
	td {
	height: 88px;
	}
	.mainList .content .left {
		width: 192px;
		float: left;
		border: 1px solid #d3d3d3;
		height: 1039px;
		text-align: center;
	}






	</style>
</html>